/**
 * Framework for batch testing user profile models
 * Final project by Sergey Nepomnyachiy and Julia Polchin
 * Supervisor: Tsvi Kuflik
 *
 */
package models.content;

import java.util.Iterator;
import java.util.Vector;

import core.environment.fVector;

/**
 * @author Sergey and Julia
 *
 */
public class Facade {
	private static Integer k = 8;
	private IDF idf;
	public Facade(Integer indexId) {
		System.out.println("user " + indexId + " <=======================");
		this.idf = new IDF(this.k);
	}
	
	public static void setK(Integer newK) { //should be called before training...
		k = newK;
	}
	
	private TFedDoc createFromInput(fVector tf) {
		Iterator<Object> it = tf.iterator(); 
		Integer categoryId = (Integer) it.next();
		Vector<Double> tfs = new Vector<Double>(tf.size());
		while (it.hasNext() ) {
			tfs.add( (Double) it.next());
		}
		
		return new TFedDoc(categoryId,tfs);
	}
	
	public void trainDoc(fVector tf) {
		System.out.println("train with:" + tf);
		this.idf.addDoc(createFromInput(tf));
	}
	
	public Integer predictCategory(fVector newDoc) {
		Integer result = this.idf.predictCategory(createFromInput(newDoc));
		System.out.println("predict: " + result + " on " + newDoc);
		return result;
	}
}
